/**
 * 
 */

import java.awt.*;
import javax.swing.*;

/**
 * @author superzhb87
 *
 */
public class testField extends JFrame{
	/**
	 * @param args
	 */

	private JPanel panel;
	private JLabel left, total;
	private Robot myRobs[];
	int numberOfRobs = 9;
	int frames = 10000;
	public static void main(String[] args) {
		int size = 500;
		
		testField frame = new testField();
		frame.setSize(size + 300, size + 100);
		frame.createGUI(size);
		frame.show();
		
		frame.run();
		


	}

	private void run(){
		int initX = 100, initY = 100;
		int num = 0;
		myRobs = new Robot[numberOfRobs];

		

		myRobs[0] = new Robot(panel, 80, 200, Math.PI/4, false);
		myRobs[1] = new Robot(panel, 100, 150, Math.PI/4, false);
		myRobs[2] = new Robot(panel, 400, 220, Math.PI/4, false);
		myRobs[3] = new Robot(panel, 300, 200, Math.PI/4, false);
		myRobs[4] = new Robot(panel, 120, 270, Math.PI/4, false);
		myRobs[5] = new Robot(panel, 100, 400, Math.PI/4, false);
		myRobs[6] = new Robot(panel, 200, 400, Math.PI/4, false);
		myRobs[7] = new Robot(panel, 480, 290, Math.PI/4, false);
		myRobs[8] = new Robot(panel, 130, 400, Math.PI/4, false);
		
/*
		for(int i = 200; i <= 300; i ++){
			Robot.field[200][i] = 1;
			Robot.field[300][i] = 1;
			Robot.field[i][200] = 1;
			Robot.field[i][300]	= 1;
		}
*/		
		for(int i = 300; i <= 310; i ++){
			Robot.field[300][i] = 1;
			Robot.field[310][i] = 1;
			Robot.field[i][300] = 1;
			Robot.field[i][310] = 1;
		}
		while(frames >= 0){
			left.setText(" " +  frames + " ");
			for(int i = 0; i < numberOfRobs; i ++)
				myRobs[i].report();
			for(int i = 0; i < numberOfRobs; i ++)
				myRobs[i].draw();
			for(int i = 0; i < numberOfRobs; i ++)
				myRobs[i].shine();
			
			panel.getGraphics().setColor(Color.BLACK);
			panel.getGraphics().fillRect(300, 300, 10, 10);
//			panel.getGraphics().fillRect(200, 200, 100, 100);
			for(int i = 0; i < 500; i ++)
				for(int j = 0; j < 500; j ++){
//					if(Robot.weakInfraredNew[i][j])
//						panel.getGraphics().drawLine(i, j, i, j);
					Robot.weakInfraredOld[i][j] = Robot.weakInfraredNew[i][j];
					Robot.weakInfraredNew[i][j] = false;
					Graphics paper = panel.getGraphics();
					for(int k = 0; k < 8; k ++){
/*						if(Robot.infraredNew[i][j][k]){
							switch (k){
							case 0: paper.setColor(Color.yellow); break;
							case 1: paper.setColor(Color.green); break;
							case 2: paper.setColor(Color.blue); break;
							case 3: paper.setColor(Color.pink); break;
							case 4: paper.setColor(Color.red); break;
							case 5: paper.setColor(Color.orange); break;
							case 6: paper.setColor(Color.magenta); break;
							case 7: paper.setColor(Color.GREEN); break;
							}
							paper.drawLine(i, j, i, j);
						}
*/
						Robot.infraredOld[i][j][k] = Robot.infraredNew[i][j][k];
						Robot.infraredNew[i][j][k] = false;
					}
				}
			
			for(int i = 0; i < numberOfRobs; i ++)
				myRobs[i].delete();
			
			for(int i = 0; i < numberOfRobs; i ++)
				myRobs[i].nextMove();


			frames --;


		}
		for(int i = 0; i < numberOfRobs; i ++)
			myRobs[i].output.close();
		
	}
	
	private void createGUI(int size){
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		Container window = getContentPane();
		window.setLayout(new FlowLayout());
		
	    panel = new JPanel();
	    panel.setPreferredSize(new Dimension(size,size));
	    panel.setBackground(Color.WHITE);
	    window.add(panel);
	    
	    left = new JLabel(" " + frames + " ");
	    window.add(left);
	    
	    total = new JLabel(" " + frames + "");
	    window.add(total);
	}
}
